<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class System_model extends CI_Model {
	
	function __construct(){
        parent::__construct();
    }
    
    function borrow_repay(){
    	$today = time();
		$yestoday = strtotime(date('Y-m-d'));
		$nextday = strtotime(date('Y-m-d 23:59:59'));
		
		// ****** 标的分期到今日还款
        //$nextday=1440777600;
        //$yestoday=1440604800;
 		$sql_result = "SELECT  id,user_id FROM rsh_borrow_repayment 
 		WHERE  repayment_time<=$nextday and repayment_time>=$yestoday
 		AND (fstatus = 2 or fstatus = 0 ) ORDER BY id";
		
    	$query = $this->db->query($sql_result);
    	
		return $query->result_array();
    }
    
	function lzborrow_repay(){
    	$today 		= time();
		$yestoday 	= strtotime(date('Y-m-d'));
		$nextday 	= strtotime(date('Y-m-d 23:59:59'));
 		$sql_result = " SELECT p1.id,p1.user_id 
 						FROM rsh_borrow_collection AS p1 LEFT JOIN rsh_borrow AS p2 ON p1.borrow_id=p2.id
						WHERE p1.repay_time>=$yestoday AND p1.repay_time<=$nextday AND 
						p1.fstatus=0 AND p2.fstatus=3 AND p2.work_time=1 ORDER BY p1.id";
 		
    	$query = $this->db->query($sql_result);
		return $query->result_array();
    }
        
    /**
     * 
     * 查找需要复审的标
     */
    function borrow_reverify(){
    	$sql_result = " SELECT * FROM rsh_borrow where account = account_yes and fstatus=1 "; 		
    	$query = $this->db->query($sql_result);
		return $query->result_array();
    }
        
    
    function slborrow_repay(){
    	$yestoday 	= strtotime(date('Y-m-d'));
		$nextday 	= strtotime(date('Y-m-d 23:59:59'));
 		$sql_result = " SELECT p1.id,p1.user_id 
 						FROM rsh_borrow_collection AS p1 LEFT JOIN rsh_borrow AS p2 ON p1.borrow_id=p2.id
						WHERE p1.repay_time<=$nextday AND 
						p1.fstatus=0 AND p2.fstatus=3 AND p2.ftype=6 ORDER BY p1.id";
 		
    	$query = $this->db->query($sql_result);
		return $query->result_array();
    }
    

	function liubiao(){
 		$sql_result = "SELECT id,user_id FROM rsh_borrow where fstatus=1 and verify_time+valid_time*24*60*60<".time();
    	$query = $this->db->query($sql_result);
		return $query->result_array();
    }

    
    //****** by iub 20141229
    function query($_sql,$flag =0){
   		$query = $this->db->query($_sql);
   		if($flag == 0 ){// 查询
   			return $query->result_array();
   		}
    }
    
    
    
    
    
}    